﻿using System;
using Tunynet;
using Tunynet.Events;
using Tunynet.Globalization;
using Tunynet.Logging;
using Spacebuilder.Common;

namespace Spacebuilder.Group.EventModules
{
    /// <summary>
    /// 删除商户会员日子
    /// </summary>
    public class GroupMemberOperationLogEventModule : IEventMoudle
    {


        /// <summary>
        /// 注册事件处理程序
        /// </summary>
        void IEventMoudle.RegisterEventHandler()
        {
            EventBus<GroupMember>.Instance().After += new CommonEventHandler<GroupMember, CommonEventArgs>(GroupOperationLogEventModule_After);
        }


        /// <summary>
        /// 商户操作日志事件处理
        /// </summary>
        private void GroupOperationLogEventModule_After(GroupMember senders, CommonEventArgs eventArgs)
        {
            var group = new GroupService().Get(senders.GroupId);
            if (group == null)
                return;
                OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo);
                entry.ApplicationId = entry.ApplicationId;
                entry.Source = GroupConfig.Instance().ApplicationName;
                entry.OperationType = eventArgs.EventOperationType;
                entry.OperationObjectName = senders.User.UserName;
                entry.OperationObjectId = senders.UserId;
                entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "商户成员", entry.OperationObjectName);

                OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>();
                logService.Create(entry);
        }
    }
}